<% layout('/layouts/default.html', {title: '活动管理', libs: ['validate','fileupload', 'ueditor', 'dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-title">
				<i class="fa icon-note"></i>
				${text(action=='audit'? '审核活动':(kjActivity.isNewRecord ? '新增活动' : '编辑活动'))}
			</div>
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${kjActivity}" action="${ctx}/kj/kjActivity/save" method="post" class="form-horizontal">
			<div class="box-body">
				<div class="form-unit">${text('基本信息')}</div>
				<#form:hidden path="id"/>
				<#form:hidden name="action" id="action"/>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('活动名')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="name" autocomplete="off" maxlength="255" class="form-control required"/>
							</div>
						</div>
					</div>

						<div class="col-xs-6">
							<div class="form-group">
								<label class="control-label col-sm-4" title="">
									<span class="required">*</span> ${text('所属城市')}：<i class="fa icon-question hide"></i></label>
								<div class="col-sm-8">

									<#form:listselect id="testUser3" title="城市选择"
									path="kjCity.id"   labelPath="kjCity.name"
									url="${ctx}/kj/kjCity/kjCitySelect?pageSize=1000" allowClear="false"
									checkbox="false" itemCode="id" itemName="name" class="required"/>
								</div>
							</div>
						</div>

					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required">*</span> ${text('是否热门活动')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="isHot" dictType="sys_yes_no" class="form-control required"/>
							</div>
						</div>
					</div>


					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required">*</span> ${text('排序(仅限热门活动，值越大越靠前)')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="isort"  class="form-control digits"/>
							</div>
						</div>
					</div>
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required">*</span> ${text('封面图(670*330)')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-10">
<!--								<#form:input path="img" maxlength="255" class="form-control"/>-->

								<#form:fileupload id="uploadImage2" returnPath="true"
								filePathInputId="img" maxUploadNum="1"
								uploadType="image" class="required " readonly="false"/>
								<#form:input path="img" class="form-control hide"/>

							</div>
						</div>
					</div>
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required">*</span> ${text('banner图(710*385)')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-10">

								<#form:fileupload id="uploadImage3" returnPath="true"
								filePathInputId="banner" maxUploadNum="3"
								uploadType="image" class="required " readonly="false"/>
								<#form:input path="banner" class="form-control hide"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required">*</span> ${text('活动开始时间')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="startTime" readonly="true" maxlength="20" class="form-control laydate required"
								dataFormat="datetime" data-type="datetime" data-format="yyyy-MM-dd HH:mm" data-done="updateMinTime(this, '#endTime')"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required">*</span> ${text('活动结束时间')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="endTime" readonly="true" maxlength="20" class="form-control laydate required"
								dataFormat="datetime" data-type="datetime" data-format="yyyy-MM-dd HH:mm"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required">*</span> ${text('报名开始时间')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="signStartTime" readonly="true"  maxlength="20" class="form-control laydate  required"
								dataFormat="datetime" data-type="datetime" data-format="yyyy-MM-dd HH:mm"  data-done="signEndTime.click()"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required">*</span> ${text('报名结束时间')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="signEndTime" readonly="true" maxlength="20" class="form-control laydate required"
								dataFormat="datetime" data-type="datetime" data-format="yyyy-MM-dd HH:mm"/>
							</div>
						</div>
					</div>
					<div class="row">

						<div class="col-xs-6">
							<div class="form-group">
								<label class="control-label col-sm-4" title="">
									<span class="required">*</span> ${text('服务地点')}：<i class="fa icon-question hide"></i></label>
								<div class="col-sm-8">
									<#form:input path="location" maxlength="9999" class="form-control required"/>
								</div>
							</div>
						</div>
					</div>
					<div class="row">
						<div class="col-xs-6">
							<div class="form-group">
								<label class="control-label col-sm-4" title="">
									<span class="required">*</span> ${text('联系人')}：<i class="fa icon-question hide"></i></label>
								<div class="col-sm-8">
									<#form:input path="leader" maxlength="255" class="form-control required"/>
								</div>
							</div>
						</div>
						<div class="col-xs-6">
							<div class="form-group">
								<label class="control-label col-sm-4" title="">
									<span class="required">*</span> ${text('联系人电话')}：<i class="fa icon-question hide"></i></label>
								<div class="col-sm-8">
									<#form:input path="leaderPhone" maxlength="255" class="form-control phone required"/>
								</div>
							</div>
						</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('入群二维码')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">

								<#form:fileupload id="uploadImage4" returnPath="true"
								filePathInputId="groupQrcode" maxUploadNum="1"
								uploadType="image" class="required " readonly="false"/>
								<#form:input path="groupQrcode" class="form-control hide"/>

							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required">*</span> ${text('活动介绍')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-10">
								<#form:ueditor height="300" simpleToolbars="false" path="content" rows="6" class="form-control required"/>
							</div>
						</div>
					</div>
				</div>
					<div class="row">
						<div class="col-xs-12">
							<div class="form-group">
								<label class="control-label col-sm-2" title="">
									<span class="required">*</span> ${text('活动岗位')}：<i class="fa icon-question hide"></i></label>
								<div class="col-sm-10">
									<table id="activityJobGrid"></table>
									<a href="#" id="activityJobGridAddRowBtn" class="btn btn-primary btn-sm mt10 mb10"><i class="fa fa-plus"></i> ${text('增行')}</a>
								</div>
							</div>
						</div>
					</div>
					<% if (hasPermi('kj:kjActivity:audit') && action == 'audit'){ %>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('审核备注（拒绝必须说明理由）')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:textarea path="remarks" id="remarks" rows="4" maxlength="500" class="form-control "/>
							</div>
						</div>
					</div>
					<% } %>
				</div>
			</div>
			<div class="box-footer">
				<div class="row">
					<div class="col-sm-offset-2 col-sm-10">
						<% if (hasPermi('kj:kjActivity:audit') && action == 'audit'){ %>
						<button type="submit" class="btn btn-sm btn-primary" id="btnSubmits"><i class="fa fa-check"></i> ${text('通 过')}</button>&nbsp;
						<button type="submit" class="btn btn-sm btn-primary" id="btnRejects"><i class="fa fa-check"></i> ${text('拒 绝 ')}</button>&nbsp;
						<% } %>
						<% else { %>
						<% if (hasPermi('kj:kjActivity:edit') && (hasPermi('kj:kjActivity:audit') || kjActivity.activityAudit!='1')){ %>
							<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;
						<% } %>
						<% } %>
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
					</div>
				</div>
			</div>
		</#form:form>
	</div>
</div>
<% } %>
<script>
	$('#btnSubmits').click(function(){
		$('#remarks').attr("class","form-control");
		$('#action').val('submit');
		$('#inputForm').attr("action","${ctx}/kj/kjActivity/audit");
	})
	$('#btnRejects').click(function(){
		$('#remarks').attr("class","form-control required");
		$('#action').val('reject');
		$('#inputForm').attr("action","${ctx}/kj/kjActivity/audit");
	})

	$("#activityJobGrid").dataGrid({
		data: ${toJson(kjActivity.activityJobList)},
		datatype: "local", // 设置本地数据
		columnModel: [
			{header:'${text("id")}', name:'id', width:100, editable:true, edittype:'text', classes: 'form-control  hide'},
			{header:'${text("岗位类型名")}', name:'jobTypeName', width:100, editable:true, edittype:'text', classes: 'form-control  hide'},
			{header:'<span class="required ">*</span>${text("岗位名")}', name:'jobName', width:100, editable:true, edittype:'text', editoptions:{'maxlength':'200', 'class':'form-control required'}},
			{header:'<span class="required ">*</span>${text("限制人数")}', name:'limitNum', width:100, editable:true, edittype:'text', editoptions:{'maxlength':'200', 'class':'form-control digits required'}},
			{header:'<span class="required ">*</span>${text("服务时长")}', name:'serviceTime', width:100, editable:true, edittype:'text', editoptions:{'maxlength':'200', 'class':'form-control number required'}},
			{header:'<span class="required ">*</span>${text("可获得积分")}', name:'integrals', width:100, editable:true, edittype:'text', editoptions:{'maxlength':'200', 'class':'form-control number required'}},
			{header:'<span class="required ">*</span>${text("岗位介绍")}', name:'remarks', width:100, editable:true, edittype:'text', editoptions:{'maxlength':'200', 'class':'form-control required'}},
			{header:'<span class="required ">*</span>岗位类型', name:'jobTypeId', width:100,
				editable:true, edittype:'select', editoptions:{'class':'form-control required',
					items: $.merge([{typeName:'&nbsp;',id:''}], ${jobTypes}),
					itemLabel: 'typeName', itemValue: 'id', dataInit: function(element){
						$(element).select2().on("change",function(){
							var rowId = $(element).attr('rowid');
							$("#" + rowId + '_jobTypeName').val($(this).find('option:selected').text());
						});
					}
				}, unformat: function(val, obj, cell){return $('#'+obj.rowId+'_'+obj.colModel.name, cell).val();}
			},
			{header:'${text("操作")}', name:'actions', width:100, sortable:false, fixed:true, formatter: function(val, obj, row, act){
					var actions = [];
					// actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#activityDetailGrid\').dataGrid(\'delRowData\',\''+obj.rowId+'\')});return false;">往后复制3条</a>&nbsp;');
					actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#activityJobGrid\').dataGrid(\'delRowData\',\''+obj.rowId+'\')});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
					return actions.join('');
				}, editoptions: {defaultValue: 'new'}}
		],
		autoGridHeight: function(){return 'auto'}, // 设置自动高度

		// 编辑表格参数
		editGrid: true,				// 是否是编辑表格
		editGridInitRowNum: 0,		// 编辑表格的初始化新增行数
		editGridAddRowBtn: $('#activityJobGridAddRowBtn'),	// 子表增行按钮
		editGridAddRowInitData: {id: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据

		// 编辑表格的提交数据参数
		editGridInputFormListName: 'activityJobList', // 提交的数据列表名
		editGridInputFormListAttrs: 'id,jobName,limitNum, remarks, serviceTime, integrals, jobTypeId, jobTypeName', // 提交数据列表的属性字段

		ajaxSuccess: function(){

		}
	});
if(${toJson(kjActivity.activityJobList)}.length == 0){
	$('#activityJobGridAddRowBtn').click();
	}
$("#inputForm").validate({
	submitHandler: function(form){
		js.ajaxSubmitForm($(form), function(data){
			js.showMessage(data.message);
			if(data.result == Global.TRUE){
				js.closeCurrentTabPage(function(contentWindow){
					contentWindow.page();
				});
			}
		}, "json");
    }
});

</script>
